@extends('activity::layout.bootstrap_modal')

@section('modal_class')
    modal-lg
@stop

@section('title')
    选择活动
@stop

@section('after-styles-end')
    {!! Html::style(env("APP_URL").'/assets/backend/libs/ladda/ladda-themeless.min.css') !!}
@stop

@section('body')
    <div class="row">

        <div class="panel-body">
            <h3 class="header">请选择活动：</h3>
            <div class="table-responsive" id="goodsList">
                <table class="table table-hover table-striped">
                    <thead>
                    <!--tr-th start-->
                    <tr>
                        <th>活动名称</th>
                        <th>类型</th>
                        <th>活动起止时间</th>
                        <th>操作</th>
                    </tr>
                    <!--tr-th end-->
                    </thead>

                    <tbody class="page-activity-list">

                    </tbody>
                </table>
            </div><!-- /.box-body -->

            <div class="pages">

            </div>
        </div>
    </div>


    <script type="text/html" id="page-temp">
        <tr>
            <td>
                {#title#}
            </td>
            <td>
                {#type#}
            </td>
            <td>
                {#starts_at#}<br>
                {#ends_at#}
            </td>
            <td>
                <button  onclick="changeSelect(this)" class="btn btn-circle {#class#}"
                        type="button" data-id="{#id#}"><i class="fa fa-{#icon#}"></i>
                </button>
            </td>
        </tr>
    </script>
@stop
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/spin.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.jquery.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/loader/jquery.loader.min.js') !!}


@section('footer')
    <input type="hidden" id="temp_selected_activity">
    <button type="button" class="btn btn-link" data-dismiss="modal">取消</button>
    <button type="button" class="ladda-button btn btn-primary" onclick="sendIds()"> 确定</button>

    @include('activity::discount.includes.modal.script')
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/common.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/jquery.http.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/page/jquery.pages.js') !!}
    <script>

        function getList() {

            var postUrl = '{{route('activity.admin.discount.modal.getModalActivityData')}}';

            $('.pages').pages({
                page: 1,
                url: postUrl,
                get: $.http.post.bind($.http),

                body: paraActivity,
                marks: {
                    total: 'data.last_page',
                    index: 'data.current_page',
                    data: 'data'
                }
            }, function (data) {
                var html = '';
                var ids = data.ids;

                data.data.forEach(function (item) {
                    if (!~ids.indexOf(String(item.id))) {
                        item.class = 'btn-warning unselect';
                        item.icon = 'times';

                    } else {
                        item.class = 'btn-info select';
                        item.icon = 'check';
                    }

                    html += $.convertTemplate('#page-temp', item, '');
                });
                $('.page-activity-list').html(html);
            });
        }

        $(document).ready(function () {
            $('#temp_selected_activity').val($('#selected_activity').val());
            paraActivity.ids=$('#temp_selected_activity').val();

            getList();
        });
    </script>
@stop






